<template>
  <div>
    <van-nav-bar
      title="我的影评"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="commentList">
      <div v-for="item in myComment" :key="item">
        <div class="box">
          <!-- {{item}} -->
          <div>
            {{ $moment(parseInt(item.create_time)).format("YYYY-MM-DD HH:mm") }}
          </div>
          <div>电影《{{ item.movie_id }}》</div>
          <div class="content">{{ item.content }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dycard from "../../components/dyCard";
import axios from "axios";
export default {
  components: {
    dycard,
  },
  data() {
    return {
      myComment: [],
    };
  },
  created() {
    this.getMyComment();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getMyComment() {
      axios
        .get(
          `http://localhost:8888/comment/myComment?username=${sessionStorage.getItem(
            "username"
          )}`
        )
        .then((res) => {
          console.log(res);
          this.myComment = res.data;
          for (var item of this.myComment) {
            axios
              .get(
                `http://localhost:8888/movie/findById?movie_id='${item.movie_id}'`
              )
              .then((res) => {
                // console.log(res)
                Object.defineProperty(item, "movie_name", {
                  value: res.data[0].movie_name,
                  enumerable: true,
                  configurable: true,
                });
              });
          }
        });
    },
  },
};
</script>

<style>
.commentList {
  width: 100%;
}
.box {
  width: 85%;
  padding: 15px;
}
.content {
  font-size: 12px;
  margin-top: 10px;
  text-align: left;
  margin-left: 10px;
}
</style>
